package org.breathe.dynamic.thread.pool.starter.mysql.config;

import org.breathe.thread.pool.common.entity.BreatheDtpProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

/**
 * @author: breathe
 * @createTime: 2025-05-19
 */
@Component
public class MysqlConfigProvider {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private BreatheDtpProperties breatheDtpProperties;
    public String getConfigJson() {
        BreatheDtpProperties.Mysql mysql = breatheDtpProperties.getMysql();
        String tableName = mysql.getTableName();
        String columnName = mysql.getColumnName();
        String configKey = mysql.getConfigKey();
        String sql = "SELECT " + columnName + " FROM " + tableName + " WHERE " + configKey + " = ?;";
        return jdbcTemplate.queryForObject(sql, String.class, mysql.getConfigValue());
    }
}
